const Router = require('koa-router')
const router = new Router()
const query = require('../db/query')

router.get('/categories', async (ctx) => {
  try {
    const sql = `
      SELECT id, name, icon 
      FROM categories 
      ORDER BY sort ASC
    `
    const result = await query(sql)
    ctx.body = {
      code: 0,
      data: result,
      msg: 'success'
    }
  } catch (error) {
    ctx.body = {
      code: 1,
      msg: error.message
    }
  }
})

module.exports = router